﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using SmartCity.Shared;

namespace CommonService.Host.EntityFrameworkCore
{
    /// <summary>
    /// 公共服务迁移数据上下文工厂
    /// </summary>
    public class CommonServiceMigrationDbContextFactory : IDesignTimeDbContextFactory<CommonServiceMigrationDbContext>
    {
        public CommonServiceMigrationDbContext CreateDbContext(string[] args)
        {
            var configuration = ConfigHelper.BuildConfiguration();
            var builder = new DbContextOptionsBuilder<CommonServiceMigrationDbContext>()
                .UseSqlServer(configuration.GetConnectionString("CommonManagement"));
            return new CommonServiceMigrationDbContext(builder.Options);
        }
    }
}